#!/bin/bash

if [ $# -lt 1 ]
then
	echo "usage"
    echo "	$0 <first-args>"
    exit
fi


input=$1
keepalived_conf="/etc/keepalived/keepalived.conf"

result=`ps aux | grep -v "grep"| grep -v  "$0"| grep -c ${input}`
if [ "${result}" -gt 0 ]; then
	if [ "${input}" ==  "keepalived" ]; then
		# vip=`grep dev ${keepalived_conf} | cut -d '/' -f 1 | sed 's/[[:blank:]]*//g'`
		# result=`curl -m 10 -w %{http_code} -s "http://${vip}:6060/aaa/appstatus"   | grep -c 200`
		result=`/etc/init.d/keepalived status | grep -c 'running...'`
	fi

	if [ "${input}" ==  "haproxy" ]; then
		result=`curl -m 10 -w %{http_code} -s "http://127.0.0.1:6060/aaa/appstatus"   | grep -c 200`
	fi
fi
echo "$result"